package com.hzcx.app.simplechat.ui.publicui.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.model.LoginModel;
import com.hzcx.app.simplechat.model.PublicModel;
import com.hzcx.app.simplechat.ui.login.bean.LoginInfoBean;
import com.hzcx.app.simplechat.ui.login.bean.PhoneCityBean;
import com.hzcx.app.simplechat.ui.login.contract.PhoneCityContract;
import com.hzcx.app.simplechat.ui.publicui.bean.ProtocolBean;
import com.hzcx.app.simplechat.ui.publicui.contract.SendCodeContract;

import java.util.List;

public class SendCodePresenter extends BasePresenter<SendCodeContract.View> implements SendCodeContract.Presenter {


    /**
     * 发送验证码
     *
     * @param context
     * @param event
     */
    @Override
    public void sendCode(Context context, String mobile, String event, String area_code) {
        PublicModel.sendCode(context, mobile, event, area_code, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.sendSuccess();
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.sendFail();
            }
        });
    }

    /**
     * 验证码登录
     *
     * @param context
     * @param mobile
     * @param captcha
     */
    @Override
    public void loginByCode(Context context, String mobile, String captcha,String area_code) {
        LoginModel.loginByCode(context, mobile, captcha,area_code, new BaseDialogObserver<LoginInfoBean>(context) {
            @Override
            protected void onSuccess(LoginInfoBean data) {
                mView.loginSuccess(data);
            }
        });
    }

    /**
     *  验证验证码是否正确
     * @param context
     * @param mobile
     * @param captcha
     * @param event
     */
    @Override
    public void checkCode(Context context, String mobile, String captcha, String event) {
        PublicModel.checkCode(context, mobile, captcha, event, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.checkCodeSuccess();
            }
        });
    }

    /**
     *  获取协议内容
     * @param context
     * @param type
     */
    @Override
    public void getProtocol(Context context, String type) {
        PublicModel.getProtocolByType(context, type, new BaseDialogObserver<ProtocolBean>(context) {
            @Override
            protected void onSuccess(ProtocolBean data) {
                mView.protocolResult(data);
            }
        });
    }
}
